// 打包时代码压缩配置
const CompressionWebpackPlugin = require('compression-webpack-plugin');
module.exports = {
  chainWebpack: (config) => {
    config.resolve.alias.set('@', resolve('src')).set('assets', resolve('src/assets')).set('components', resolve('src/components')).set('base', resolve('baseConfig')).set('public', resolve('public'));
  },
  chainWebpack: (config) => {
    config.plugins.delete('prefetch');
    if (process.env.NODE_ENV !== 'development') {
      // 对超过10kb的文件gzip压缩
      config.plugin('compressionPlugin').use(
        new CompressionWebpackPlugin({
          test: /\.(js|css|html)$/,
          threshold: 10240,
        })
      );
    }
  },
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-plugin-px2rem')({
            rootValue: 37.5,
            exclude: /(node_module)/,
            selectorBlackList: ['.van'],
            propList: ['*'],
            mediaQuery: false,
            minPixelValue: 2,
          }),
        ],
      },
    },
  },
  publicPath: './',
  lintOnSave: false,
  productionSourceMap: false,
  devServer: {
    disableHostCheck: true,
    overlay: {
      errors: true,
    },
    // inline: true, // 源文件改动时会自动刷新
    // hot: true, // 摸块热跟新
    // public: '192.168.1.111',
    // compress: true, // 开启gzip压缩
  },

  // 根据环境来判断是否关闭控制台输出
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
    }
  },
};